package com.outfoodmanage.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author huisonglin
 * @Description
 * @PackageName intelligent-vehicle-platform
 * @Package com.intelligent.utils
 * @Date 2023/7/20 13:03
 * @Version 1.0
 */
public class PositionUtil {

    public static String getAddress(String lon,String lat){
        try {
            String address = HttpUtils.sendGet("https://apis.map.qq.com/ws/geocoder/v1", "location="+(lat+","+lon)+"&key=DW2BZ-RWYKV-AD4PF-UYA4Q-K2FRZ-L2B3K");
            JSONObject jsonObject = JSON.parseObject(address);
            String string = jsonObject.getJSONObject("result").getJSONObject("formatted_addresses").getString("recommend");
            return string;
        } catch (Exception e) {
            e.printStackTrace();
            return "未知地点";
        }
    }

    public static String parsePostion(String position){
        int i = Integer.parseInt(position, 16);
        BigDecimal divide = new BigDecimal(i).divide(new BigDecimal("1800000"),6, RoundingMode.HALF_DOWN);
        System.out.println(divide);
        return divide.toString();
    };
}
